package com.watchthelan.service.administrator;

import java.util.ArrayList;
import java.util.List;

import com.watchthelan.domain.Administrator;
import com.watchthelan.repository.AdministratorDao;
import com.watchthelan.repository.InMemoryAdministratorDao;

import junit.framework.TestCase;

public class SimpleAdministratorManagerTests extends TestCase {
	private SimpleAdministratorManager administratorManager;
	private List<Administrator> administrators;
	
	private String ADM_1_NAME = "Pop Vasile";
	private String ADM_1_UNAME = "pop";
	private String ADM_1_PASS = "pop";
	
	private String ADM_2_NAME = "Iorgu Petru";
	private String ADM_2_UNAME = "petru";
	private String ADM_2_PASS = "petru";
		
	protected void setUp() throws Exception {
		administratorManager = new SimpleAdministratorManager();
		administrators = new ArrayList<Administrator>();
		
		Administrator administrator = new Administrator();
		administrator.setName(ADM_1_NAME);
		administrator.setUsername(ADM_1_UNAME);
		administrator.setPassword(ADM_1_PASS);
		
		administrators.add(administrator);
		AdministratorDao administratorDao = new InMemoryAdministratorDao(this.administrators);
		administratorManager.setAdministratorDao(administratorDao);
	}
	
	public void testGetAdministrators() {
		assertEquals(this.administrators, administratorManager.getAdministrators());
	}
	
	public void testAddAdministrator() {
		int num_of_administrators = this.administrators.size();		
		Administrator administrator = new Administrator();
		administrator.setName(ADM_2_NAME);
		administrator.setUsername(ADM_2_UNAME);
		administrator.setPassword(ADM_2_PASS);
		
		administratorManager.addAdministrator(administrator);
		// Verify if list has grow
		
		assertEquals(num_of_administrators + 1, administrators.size());
		assertEquals(administrators.size(), administratorManager.getAdministrators().size());
	}
	
	public void testDeleteAdministratorById() {
		Administrator administrator = new Administrator();

		// Get an administrator
		for (Administrator a: administrators) {
			if (ADM_2_NAME.equals(a.getName())) {
				administrator = a;
			}
		}
		if (administrator != null) {
			administratorManager.deleteAdministratorById(administrator.getId());
			assertNull(administratorManager.getAdministratorById(administrator.getId()));
		} else {
			fail("Admistrators list is empty");
		}
	}
	
	public void testUpdateAdministrator() {
		// TODO:
	}
	
	public void testGetAdministratorById() {
		// TODO:
	}
}
